package org.ssp.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 * 安全退出
 */
@WebServlet("/logout")
public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if(request.getSession().getAttribute("assist")==null){
			JSONObject json=new JSONObject();
			json.element("success", false);
			PrintWriter out=response.getWriter();
			out.write(json.toString());
			return;
		}
		request.getSession().removeAttribute("assist");
		request.getSession().invalidate();//安全退出时销毁session
		JSONObject json=new JSONObject();
		json.element("success", true);
		PrintWriter out=response.getWriter();
		out.write(json.toString());
		return;
	}
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
}
